@extends('admin::layouts.master')
@section('content')
    @component('components.tabs',['title'=>'角色管理'])
        @slot('nav')
            <li class="nav-item"><a class="nav-link active" href="#home1" data-toggle="tab" role="tab">角色列表</a></li>
            <li class="nav-item"><a class="nav-link" data-toggle="modal" data-target="#addRole" href="#profile1">添加角色</a></li>

            @component('components.modal',['id'=>"addRole",'title'=>"添加角色","url"=>"/admin/role"])
                <div class="form-group">
                    <label>角色名称</label>
                    <input class="form-control" type="text" placeholder="请输入中文角色名称" name="title" value="{{old('title')}}">
                </div>
                <div class="form-group">
                    <label>角色标识</label>
                    <input class="form-control" type="text" placeholder="标识必须为英文字母" name="name" value="{{old('name')}}">
                </div>
            @endcomponent
        @endslot
        @slot('content')
                <table class="table table-striped table-borderless">
                    <thead>
                    <tr>
                        <th style="width: 10%;">编号</th>
                        <th style="width: 30%;">角色名称</th>
                        <th style="width:20%;">角色标识</th>
                        <th style="width:20%;">创建时间</th>
                        <th class="actions" style="width:5%;"></th>
                    </tr>
                    </thead>
                    <tbody class="no-border-x">
                    @foreach($roles as $role)
                        <tr>
                            <td>{{$role['id']}}</td>
                            <td>{{$role['title']}}</td>
                            <td>{{$role['name']}}</td>
                            <td class="text-success">{{$role['created_at']}}</td>
                            <td class="actions">
                                <div class="btn-group btn-space">
                                    <button class="btn btn-secondary" type="button" onclick="delRole({{$role['id']}},this)">删除</button>
                                    <form action="/admin/role/{{$role['id']}}" method="post">
                                        @csrf
                                        @method("DELETE")
                                    </form>
                                    <a href="/admin/role/permission/{{ $role['id'] }}" class="btn btn-secondary" type="button">权限</a>
                                    <button class="btn btn-secondary" type="button" data-toggle="modal" data-target="#editRole{{$role['id']}}">编辑</button>
                                </div>
                                @component('components.modal',['id'=>"editRole{$role['id']}",'title'=>"编辑{$role['title']}",'method'=>'PUT',"url"=>"/admin/role/{$role['id']}"])
                                    <div class="form-group">
                                        <label>角色名称</label>
                                        <input class="form-control" type="text" placeholder="请输入中文角色名称" name="title" value="{{$role['title']}}">
                                    </div>
                                    <div class="form-group">
                                        <label>角色标识</label>
                                        <input class="form-control" type="text" placeholder="标识必须为英文字母" name="name" value="{{$role['name']}}">
                                    </div>
                                @endcomponent
                            </td>


                        </tr>
                    @endforeach
                    </tbody>
                </table>

        @endslot
    @endcomponent
@endsection
@section('script')
    <script>
        function delRole(id,ct)
        {
            if(confirm("确认删除?")){
                $(ct).next('form').trigger('submit');
            }
        }
    </script>
@endsection
